package com.example.controller;

import java.util.List;

import com.example.pojo.SaleChance;
import com.example.pojo.TCustomer;
import com.example.service.ITCustomerService;
import com.example.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageInfo;
import com.example.pojo.CustomerReprieve;
import com.example.service.ICustomerReprieveService;
import io.swagger.annotations.Api;
/**
 * <p>
 * 客户流失暂缓表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-05-10
 */
@RestController
@RequestMapping("/customerReprieve")
@Api(tags = "客户流失暂缓表",value = "")
@CrossOrigin(allowCredentials = "true")
public class CustomerReprieveController {
    @Autowired
    private ICustomerReprieveService customerReprieveService;
    @Autowired
    private ITCustomerService customerService;

    /**
     * 分页
     */
    @GetMapping("/pager")
    @ApiOperation(value = "获得客户流失暂缓表分页信息")
    public PageInfo<CustomerReprieve> displayPager(@RequestParam(defaultValue = "1")Integer pageNum,
                                                   @RequestParam(defaultValue = "5")Integer pageSize){
        return customerReprieveService.electByPager(pageNum,pageSize);
    }

    /**
     * 查询所有
     */
    @GetMapping("")
    public List<CustomerReprieve> displayCustomerReprieveInfo(){
        return customerReprieveService.selectAll();
    }

    /**
     * 确定流失
     */
    @ApiOperation(value = "确定流失")
    @PutMapping("/ls/{id}")
    public ResultVo lose(@PathVariable("id") Integer id){
        TCustomer customer = new TCustomer().setId(id).setState(2);
        if (customerService.updateById(customer)){
            return ResultVo.ok("流失成功");
        }
        return ResultVo.error("流失失败");
    }

    /**
     * 暂缓流失
     */
    @ApiOperation(value = "暂缓流失")
    @PutMapping("/zh")
    public ResultVo temporary(Integer id){
        TCustomer customer = new TCustomer().setId(id).setState(1);
        if (customerService.updateById(customer)){
            return ResultVo.ok("暂缓流失成功");
        }
        return ResultVo.error("暂缓流失失败");
    }

    /**
     * 添加暂缓
     */
    @ApiOperation(value = "添加计划项")
    @PostMapping("/add")
    public ResultVo addCustomerReprieve(@RequestBody CustomerReprieve customerReprieve){
        return customerReprieveService.addCustomerReprieve(customerReprieve);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除暂缓措施")
    @DeleteMapping("/sc/{id}")
    public ResultVo del(@PathVariable("id") Integer id){
        if(customerReprieveService.removeById(id)){
            return ResultVo.ok("修改成功。");
        }
        return ResultVo.error("修改失败!");
    }
}
